package core.cwm;

import java.util.ArrayList;
import java.util.List;

import core.obj.Invoice;
import core.obj.Object;
import core.obj.Payment;
import core.obj.StaffingReq;
import core.obj.TimeReport;

public class CompanyDataSet {

	private List<StaffingReq> staffReqs = null;
	private List<TimeReport>  timeReports =  null;
	private List<Invoice> invoices = null;
	private List<Payment> payments = null;
	
	public List<Object> getAllData() {
		List<Object> objects = new ArrayList<Object>();
		if(staffReqs != null)
			objects.addAll(staffReqs);
		if(timeReports != null)
			objects.addAll(timeReports);
		if(invoices != null)
			objects.addAll(invoices);
		if(payments != null)
			objects.addAll(payments);
		return objects;
	}

	public void setTimeReports(List<TimeReport> timeReports) {
		this.timeReports = timeReports;
	}

	public List<TimeReport> getTimeReports() {
		return timeReports;
	}
	
	public void addTimeReport(TimeReport timeReport) {
		if(timeReports == null)
			timeReports = new ArrayList<TimeReport>();
		timeReports.add(timeReport);
	}
	
	public void setInvoices(List<Invoice> invoices) {
		this.invoices = invoices;
	}

	public List<Invoice> getInvoices() {
		return invoices;
	}
	
	public void addInvoice(Invoice invoice) {
		if(invoices == null)
			invoices = new ArrayList<Invoice>();
		invoices.add(invoice);
	}
	
	public void setPayments(List<Payment> payments) {
		this.payments = payments;
	}

	public List<Payment> getPayments() {
		return payments;
	}
	
	public void addPayment(Payment payment) {
		if(payments == null)
			payments = new ArrayList<Payment>();
		payments.add(payment);
	}


	public void setStaffReqs(List<StaffingReq> staffReqs) {
		this.staffReqs = staffReqs;
	}

	public List<StaffingReq> getStaffReqs() {
		return staffReqs;
	}

	public void addStaffReq(StaffingReq staffReq) {
		if(staffReqs == null)
			staffReqs = new ArrayList<StaffingReq>();
		staffReqs.add(staffReq);
	}
	
	public boolean contains(Object obj) {
		boolean b = false;
		if(staffReqs != null)
			b = staffReqs.contains(obj);
		if(!b) {
			if(timeReports != null)
				b = timeReports.contains(obj);
			if(!b) {
				if(invoices != null)
					b = invoices.contains(obj);
				if(!b) {
					if(payments != null)
						b = payments.contains(obj);
				}
			}
		}

		return b;
	}
	
	public Object findObject(String objID) {
		if(staffReqs != null) {
			for(StaffingReq req:staffReqs) {
				if(req.getID().equals(objID)) {
					return req;
				}
			}
		}
		
		if(timeReports != null) {
			for(TimeReport obj:timeReports) {
				if(obj.getID().equals(objID)) {
					return obj;
				}
			}
		}
		
		if(invoices != null) {
			for(Invoice obj:invoices) {
				if(obj.getID().equals(objID)) {
					return obj;
				}
			}
		}
		
		if(payments != null) {
			for(Payment obj:payments) {
				if(obj.getID().equals(objID)) {
					return obj;
				}
			}
		}
		return null;
	}
	
	public void removeObject(Object obj1) {
		String objID = obj1.getID();
		if(staffReqs != null) {
			for(StaffingReq req:staffReqs) {
				if(req.getID().equals(objID)) {
					staffReqs.remove(req);
					return;
				}
			}
		}
		
		if(timeReports != null) {
			for(TimeReport obj:timeReports) {
				if(obj.getID().equals(objID)) {
					timeReports.remove(obj);
					return;
				}
			}
		}
		
		if(invoices != null) {
			for(Invoice obj:invoices) {
				if(obj.getID().equals(objID)) {
					invoices.remove(obj);
					return;
				}
			}
		}
		
		if(payments != null) {
			for(Payment obj:payments) {
				if(obj.getID().equals(objID)) {
					payments.remove(obj);
					return;
				}
			}
		}
	}	
}
